<?php include dirname(__FILE__).'/common/header.php'; ?>

<?php include dirname(__FILE__).'/common/menu.php'; ?>

var ctrlName = '<?php echo $ctrlName ?>';
var attr = {};

list.baseFrm = function(r){
    var paramsData = r ? {template_id:r.template_id}: {};
    var win = new ZM.PopUp({
        title:r ? '编辑红包模板:' + r.template_name : '新建红包模板',
        type:'s',
        items:new ZM.FormPanel({
            url:list.baseUrl +  ctrlName + (r ? '/editTemplate' : '/createTemplate'),
            params:paramsData,
            keySubmit:true,
            success:function(res) {
                ZM.bo.msg('success',res.detail);
                list.grid.store.reload();
                win.close();
            },
            items:[{
                fieldLabel:'名称',
                name:'template_name',
                value: r ? r.template_name : '',
                allowBlank:false
            },{
                xtype:'numberfield',
                fieldLabel:'金额(元)',
                name:'template_money',
                value: r ? r.template_money : '',
                allowBlank:true,
                minValue:0
            },{
              fieldLabel:'祝福语',
              name:'template_wish',
              value: r ? r.template_wish : '',
              allowBlank:false
            },{
                fieldLabel:'提供方名称',
                name:'template_support',
                value: r ? r.template_support : '',
                allowBlank:false
            }]
        })
    }).show();
}


list.statusFrm = function(r,msg,method){
    Ext.Msg.confirm('确认?',msg,function(btn) {
        if(btn != 'no') {
            ZM.ajax({
                url: list.baseUrl +  ctrlName + method,
                params:{template_id:r.template_id},
                mask:list.grid,
                success:function(res){
                    ZM.bo.msg('success!',res.detail);
                    list.grid.store.reload();
                }
            });
        }
    });
}

/*
| -------------------------------------------------------------------
|  List Grid
| -------------------------------------------------------------------
*/
list.grid = new ZM.EditorGridPanel({
	tbar:[{
		text:'新建红包模板',
		cls:'btn-show',
		hidden:!Ext.permission['template/createTemplate'.toLowerCase()],
		iconCls:'icon-create',
		handler:function() {
			list.baseFrm(false);
		}
	}],
	url: list.baseUrl + 'template/getTemplateList',
	autoExpandColumn:'aeColumn',
	columns:[
		{header:'ID',dataIndex:'template_id'},
		{header:'名称',dataIndex:'template_name',filter:{}},
		{header:'金额(元)',dataIndex:'template_money'},
		{header:'祝福语',dataIndex:'template_wish',id:'aeColumn',filter:{}},
		{header:'提供方名称',dataIndex:'template_support',width:150,filter:{}},
		//{header:'最后修改人',dataIndex:'user_name',width:75},
		{header:'最后修改时间',dataIndex:'template_time_lastmodified',width:140},
		{header:'操作',width:150,renderer:function(v,p,r){
			var str = '';
			str += Ext.rd('编辑','fireEdit',r,'template/editTemplate');
			str += Ext.rd('删除','fireDelete',r,'template/deleteTemplate','red');
			return str;
		}}
	]
});



list.grid.fireEdit = function(r) {
    var r = r.json;
    list.baseFrm(r);
}

list.grid.fireDelete = function(r) {
    var r = r.json;
    list.statusFrm(r,'确定要删除红包模板['+r.template_name+']?','/deleteTemplate');
}



<?php include dirname(__FILE__).'/common/layout.php'; ?>
list.grid.store.load();
<?php $includeEditor = true ?>
<?php include dirname(__FILE__).'/common/footer.php'; ?>
